package com.rran.study.chat.server.service.impl;

import com.alibaba.fastjson.JSON;
import com.rran.study.chat.server.dto.request.RegisterMsg;
import com.rran.study.chat.server.core.repository.ChannelResponsitory;
import com.rran.study.chat.server.dto.Response;
import com.rran.study.chat.server.service.UserService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author yy
 * @Type UserServiceImpl.java
 * @Desc
 * @date 2020/8/9 18:58
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Override
    public Response<String> register(RegisterMsg msg, ChannelHandlerContext ctx) {
        String beanId = msg.getBeanId();
        //第一次连上将beanId和ctx绑定并缓存
        ChannelResponsitory.storeChannel(beanId,ctx);
        log.info(JSON.toJSONString(ChannelResponsitory.getChannelMap()));
        String result = beanId+"注册成功";
        return new Response<>(result);
    }
}
